package com.matrix.java.chap_07;

import com.matrix.java.util.ArrayUtil;

import java.util.Scanner;

/*
    统计学方面：计算标准差
 */
public class Ex7_11 {
    public static void main(String[] args) {
        double[] array = new double[10];
        Scanner input = new Scanner(System.in);
        System.out.print("Enter ten numbers: ");
        for (int i = 0; i < array.length; i++) {
            array[i] = input.nextDouble();
        }
        input.close();
        double mean = ArrayUtil.average(array);
        System.out.printf("%.2f%n",mean);
        System.out.printf("%.5f",deviation(array));
    }

    private static double deviation(double[] array) {
        double mean = ArrayUtil.average(array);
        double sum = 0;
        for (double v : array) {
            sum += Math.pow(v - mean, 2);
        }
        return Math.sqrt(sum / (array.length - 1));
    }
}
